package com.example.renren.controller;

import java.util.Arrays;
import io.swagger.annotations.ApiOperation;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;

//import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import com.example.renren.entity.User;
import com.example.renren.service.UserService;
import com.example.renren.utils.R;



/**
 * 
 *
 * @author VSHDI
 * @email vshd1@163.com
 * @date 2020-08-05 15:52:54
 */
@RestController
@RequestMapping("renren/user")
public class UserController {
    @Autowired
    private UserService userService;

    /**
     * 列表
     */
    @GetMapping("/list")
    @ApiOperation(value="获取数据列表", notes="分页获取数据列表")
    //@RequiresPermissions("renren:user:list")
    public R list(@RequestParam(defaultValue = "1") Integer pageNo,
                  @RequestParam(defaultValue = "10") Integer pageSize){
        Page<User> page = new Page(pageNo,pageSize);
        return R.ok().put("data", userService.getByPage(page));
    }


    /**
     * 信息
     */
    @GetMapping("/info/{id}")
    @ApiOperation(value="获取一列信息", notes="根据id获取一列信息")
    //@RequiresPermissions("renren:user:info")
    public R info(@PathVariable("id") Integer id){
		User user = userService.getById(id);

        return R.ok().put("user", user);
    }

    /**
     * 保存
     */
    @PostMapping("/save")
    @ApiOperation(value="保存一列数据", notes="")
    //@RequiresPermissions("renren:user:save")
    public R save(@RequestBody User user){
		userService.save(user);

        return R.ok();
    }

    /**
     * 修改
     */
    @PostMapping("/update")
    @ApiOperation(value="更新一列数据", notes="")
    //@RequiresPermissions("renren:user:update")
    public R update(@RequestBody User user){
		userService.updateById(user);

        return R.ok();
    }

    /**
     * 删除
     */
    @PostMapping("/delete")
    @ApiOperation(value="删除一组数据", notes="根据id获取一位用户信息")
    //@RequiresPermissions("renren:user:delete")
    public R delete(@RequestBody Integer[] ids){
		userService.removeByIds(Arrays.asList(ids));

        return R.ok();
    }

}
